package com.gl.emms.whale.util;


import com.gl.emms.whale.app.Constant;

import android.content.Context;
import android.content.SharedPreferences;

public class SharePreferenceUtil {
	private SharedPreferences sp;
	private SharedPreferences.Editor editor;
	public SharePreferenceUtil(Context context) {
		sp = context.getSharedPreferences(Constant.SAVE_USERINFO, context.MODE_PRIVATE);
		editor = sp.edit();
	}
	public SharePreferenceUtil(Context context, String file) {
		sp = context.getSharedPreferences(file, context.MODE_PRIVATE);
		editor = sp.edit();
	}
	// 用户名保存
	public void setUserName(String username) {
		editor.putString("username", username);
		editor.commit();
	}

	public String getUserName() {
		return sp.getString("username", "");
	}

	// 充值金额
	public void setMoney(String Money) {
		editor.putString("money", Money);
		editor.commit();
	}

	public String getMoney() {
		return sp.getString("money", "0");
	}
	// 用户密码保存
	public void setPassword(String password) {
		editor.putString("password", password);
		editor.commit();
	}

	public String getPassword() {
		return sp.getString("password", "");
	}
	// 是否在后台运行标记
	public void setIsStart(boolean isStart) {
		editor.putBoolean("isStart", isStart);
		editor.commit();
	}

	public boolean getIsStart() {
		return sp.getBoolean("isStart", false);
	}

	// 是否第一次运行本应用
	public void setIsFirst(boolean isFirst) {
		editor.putBoolean("isFirst", isFirst);
		editor.commit();
	}

	public boolean getisFirst() {
		return sp.getBoolean("isFirst", true);
	}
	// 是否开启实时点抄
	public void setIsRealtime(boolean isRealtime) {
		editor.putBoolean("isRealtime", isRealtime);
		editor.commit();
	}

	public boolean getisRealtime() {
		return sp.getBoolean("isRealtime", false);
	}
	// 是否第一次运行本应用
	public void setId(String id) {
		editor.putString("id", id);
		editor.commit();
	}

	public String getId() {
		return sp.getString("id", "");
	}
	// 用户头像路径保存
	public void setHeadImage(String headImageUrl) {
		editor.putString("headImageUrl", headImageUrl);
		editor.commit();
	}

	public String getHeadImageUrl() {
		return sp.getString("headImageUrl", "");
	}

	// 用户头像路径保存
	public void setAutoControl(boolean[] controlEnable,String []controlTime,String [] controlType) {

		for (int i = 0; i < 4; i++) {
			editor.putBoolean("controlEnable"+i, controlEnable[i]);
			editor.putString("controlTime"+i, controlTime[i]);
			editor.putString("controlType"+i, controlType[i]);
		}
		editor.commit();
	}

	public boolean[] getAutoControlEnable() {
		boolean [] controlEnable = new boolean[4] ;
		for (int i = 0; i < 4; i++) {
			controlEnable[i] = sp.getBoolean("controlEnable"+i, false);
		}
		return controlEnable;
	}
	public String[] getAutoControlTime() {
		String [] controlTime = new String[4] ;
		for (int i = 0; i < 4; i++) {
			controlTime[i] = sp.getString("controlTime"+i, "00:00");
		}
		return controlTime;
	}
	public String[] getAutoControlType() {
		String [] controlType = new String[4] ;
		for (int i = 0; i < 4; i++) {
			controlType[i] = sp.getString("controlType"+i, "2");
		}
		return controlType;
	}
}
